﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace ChessOnline
{
    public class ServerLogger
    {
        private string logName = "server_log.txt";
        StreamWriter file;
        Queue<string> lines = new Queue<string>();

        public ServerLogger()
        {
            
        }

        public ServerLogger(string path)
        {
            logName = path;            
        }     

        public void Print(string message)
        {
            string print_msg = DateTime.Now.ToString("HH:mm:ss:ffff") + " " + message;
            Console.WriteLine(print_msg);
            lines.Enqueue(print_msg);
        }

        public void SaveLog()
        {
            int count = lines.Count;
            file = new StreamWriter(logName, false);
            for (int i = 0; i < count; i += 1)
            {
                file.WriteLine(lines.Dequeue());
            }
            file.Close();
        }
    }
}
